﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Globalization;
using System.Windows.Media;
using ReporterEngine.Model;

namespace Reporter.Converters
{
    [ValueConversion(typeof(object), typeof(Brush))]
    public class InstanceTypeToBrushConverter : IValueConverter
    {
        //categories
        public Brush InstanceGroupTypes { get; set; }
        public Brush InstanceMembers { get; set; }
        public Brush InstanceDimensions { get; set; }
        public Brush InstanceCustomCategory { get; set; }
        public Brush InstanceValues { get; set; }
        public Brush InstanceProperties { get; set; }
        public Brush InstanceReferences { get; set; }   
        public Brush InstanceUsedBys { get; set; }    

        // leaf nodes
        public Brush InstanceNode { get; set; }
        public Brush InstanceReference { get; set; }
        public Brush InstanceUsedBy { get; set; }
        public Brush InstanceProperty { get; set; }
        public Brush InstanceValue { get; set; }
     

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {                
                if (value is InstanceCategory)
                {
                    var catType = (value as InstanceCategory).CategoryType;

                    switch (catType)
                    {
                        case CategoryTypes.Properties:
                            return InstanceProperties;
                        case CategoryTypes.Referencies:
                            return InstanceReferences;
                        case CategoryTypes.UsedBy:
                            return InstanceUsedBys;
                        case CategoryTypes.InstanceGroupType:
                            return InstanceGroupTypes;
                        case CategoryTypes.Members:
                            return InstanceMembers;
                        case CategoryTypes.Dimensions:
                            return InstanceDimensions;
                        case CategoryTypes.Custom:
                            return InstanceCustomCategory;
                        case CategoryTypes.Values:
                            return InstanceValues;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                if (value is InstanceNode)
                    return InstanceNode;
                if (value is InstanceProperty)
                    return InstanceProperty;
                if (value is InstanceReference)
                    return InstanceReference;
                if (value is InstanceUsedBy)
                    return InstanceUsedBy;
                if (value is InstanceValue)
                    return InstanceValue;
                return null;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
